﻿using System;
using System.Collections.Generic;
using System.Text;
using PSE.ProcessManager.Server.Process.Security;
using Sinacor.Infra.Service.Common;
using Sinacor.Infra.Core.ProcessManager.Server.Security;
using Sinacor.Infra.Service.Security.Services;
using Sinacor.Process.Bovespa.Negocio.Server.Bovespa.Movimento.ControleMovimentoBolsa;

namespace Sinacor.Process.Bovespa.Negocio.Server.Communication
{
    public class ControleMovimentoBolsa : BaseCommunication 
    {
        #region Construtor

        public ControleMovimentoBolsa()
			: base(AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.LoginName, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.Password, AuthenticationContext<SinacorAuthenticationData>.Current.AuthenticationData.CompanyId)
		{
		}

		#endregion

		#region Métodos

		public ProcessEntity.InformacoesMovimento ObterInformacoesMovimento()
		{
            IControleMovimentoBolsa servico = null;
            Translator.DataContractToProcessEntity.ControleMovimentoBolsa translatorResponse = null;
            ProcessEntity.InformacoesMovimento retorno = null;

            try
            {
                using (ServiceInstance<IControleMovimentoBolsa> service = new ServiceInstance<IControleMovimentoBolsa>())
                {
                    servico = service.TryGetInstance(this.LoginName, this.Password, this.CompanyId);
                    translatorResponse = new Translator.DataContractToProcessEntity.ControleMovimentoBolsa();
                    retorno = translatorResponse.ToInformacoesMovimento(servico.ObterInformacoesMovimento(new DataMovimentoRequest()));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return retorno;
		}

		#endregion
    }
}
